import $axios, { Result } from '@/plugins/axios'
import { AxiosResponse } from 'axios'

/**
 * 获取用户信息
 * @returns 用户信息
 */
export async function getUserInfo(): Promise<AxiosResponse<Result>> {
  return await $axios.get('/supervision-api/backUserInfo/getUserInfo')
}

/**
 * 用户登录
 * @param data.userName 用户名
 * @param data.password 密码
 */
export async function login(data: {
  userName: string
  password: string
}): Promise<AxiosResponse<Result>> {
  return await $axios.post('/supervision-api/sysLoginUser/login', data)
}

/**
 * 用户登出
 */
export async function logout(): Promise<AxiosResponse<Result>> {
  return await $axios.get('/supervision-api/backUserInfo/logout')
}

/**
 * 修改密码
 * @param oldPassword 旧密码
 * @param newPassword 新密码
 */
export async function changePassword(
  oldPassword: string,
  newPassword: string,
): Promise<AxiosResponse<Result>> {
  return await $axios.post('/supervision-api/backUserInfo/modifyPassword', {
    olderPassword: oldPassword,
    password: newPassword,
  })
}

/**
 * 根据用户的id查询该用户全部的菜单权限
 * @param userId 用户id
 */
export async function getUserMenuList(
  userId: number,
): Promise<AxiosResponse<Result>> {
  return await $axios.get(`/supervision-api/backUserInfo/getMenuList/${userId}`)
}
